package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.tencent.mmkv.MMKV;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.enumwrap.EvalutePriceType;
import com.ygxsk.carhome.response.EvaluteCurrentItemBean;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;

import java.math.BigDecimal;
import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-17  16:07
 * @Description:评估的历史记录的  条目内容
 */
public class EvaluateHistoryListItemAdapter extends BaseQuickAdapter<EvaluteCurrentItemBean, BaseViewHolder> {
    public EvaluateHistoryListItemAdapter(int layoutResId) {
        super(layoutResId);
    }

    public EvaluateHistoryListItemAdapter(int layoutResId, @Nullable List<EvaluteCurrentItemBean> data) {
        super(layoutResId, data);
        addChildClickViewIds(R.id.textviewphoneinevaluatehistory);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, EvaluteCurrentItemBean evaluateListItemBean) {

        if (evaluateListItemBean != null) {

            //姓名
            String name = evaluateListItemBean.getCustomerName();
            //手机号
            String phone = evaluateListItemBean.getCustomerPhone();
            //车辆型号
            String carModel = evaluateListItemBean.getCarName();

            //这里应该判断评估的价格:是一口价还是价格区间：
            String priceType = evaluateListItemBean.getPriceType();

            //价格
            BigDecimal minPrice = evaluateListItemBean.getMinPrice();
            BigDecimal maxPrice = evaluateListItemBean.getMaxPrice();

            String priceResult = "";

            if (TextUtils.equals(priceType, EvalutePriceType.PRICETYPE_ONE_SINGLE.getIndex())) {

                if (minPrice != null) {
                    priceResult = minPrice.toString();
                } else {
                    priceResult = CommUtils.formatComma2BigDecimal(0.00).toString();
                }

            } else if (TextUtils.equals(priceType, EvalutePriceType.PRICETYPE_TWO_RANGE.getIndex())) {
                //如果是价格区间，那么展示两个价格

                String minPriceResult = "";
                String maxPriceResult = "";

                if (minPrice != null) {
                    minPriceResult = minPrice.toString();
                } else {
                    minPriceResult = CommUtils.formatComma2BigDecimal(0.00).toString();
                }

                if (maxPrice != null) {
                    maxPriceResult = maxPrice.toString();
                } else {
                    maxPriceResult = CommUtils.formatComma2BigDecimal(0.00).toString();
                }

                //价格区间是两个价格的连接
                // TODO: 2023-08-09 21:45 添加人民币符号
                priceResult = minPriceResult + "-" + maxPriceResult;

            }

            //标签的内容-评估车辆的方式
            String typeEvaluate = evaluateListItemBean.getEstimateTypeName();
            //状态的内容--主要是分配状态,状态的文字形式
            String satateItem = evaluateListItemBean.getStatusName();

            //findviews
            //姓名
            //评估的方式标签
            TextView textViewPersonName = (TextView) baseViewHolder.getView(R.id.textviewpersonname);
            //手机号
            TextView textViewEditViewPhone = (TextView) baseViewHolder.getView(R.id.textviewphoneinevaluatehistory);
            //车辆型号 textviewcarmodelvalue
            TextView textViewCarModelValue = (TextView) baseViewHolder.getView(R.id.textviewcarmodelvalue);
            //评估的价格
            TextView textViewCarPriceValue = (TextView) baseViewHolder.getView(R.id.textviewcarpricevalue);

            //评估的方式标签
            RoundTextView textViewEvaluateFormWhere = (RoundTextView) baseViewHolder.getView(R.id.textviewevaluateformwhere);
            //分配状态
            TextView textViewPersonEvaluateState = (TextView) baseViewHolder.getView(R.id.textviewpersonevaluatestate);

            CommUtils.setText(textViewPersonName, name);

//          CommUtils.setText(textViewEditViewPhone, phone);
            CommUtils.setText(textViewEditViewPhone, StringCodeUtils.mobileEncrypt(phone));

            CommUtils.setText(textViewCarModelValue, carModel);
            //涉及 价格和金额的 添加货币符号和单位；
            CommUtils.setText(textViewCarPriceValue, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + priceResult + StringUtils.getString(R.string.unitmoney));

            //评估的状态
            CommUtils.setText(textViewEvaluateFormWhere, typeEvaluate);
            CommUtils.setText(textViewPersonEvaluateState, satateItem);

        }

    }
}
